package TestApp;

/**
 * @version 3 11 February 2013
 * @author Myhaylo Kotsyuruba
 */

import java.io.*;
import java.util.Scanner;

public class InputOutputSystem {

    private static final Scanner SCANNER = new Scanner(System.in);
    private static final int MAX_LINE_LENGTH = 70;

    public static void show(String text) {
        System.out.println(text);
    }

    public static String getAnswer() {
        System.out.print("Your answer: ");
        return SCANNER.nextLine();
    }

    public static String getAnswer(String explanation) {
        System.out.print(explanation);
        return SCANNER.nextLine();
    }

    public static String formatString(String string) {
        String[] words = string.split(CONSTANTS.SPLASH);
        String result = "";
        int lineLength = 0;
        for (String word : words) {
            if ((lineLength + 1 + word.length()) < MAX_LINE_LENGTH) {
                result = String.format("%s%s%s", result, " ", word);
                lineLength = lineLength + 1 + word.length();
            } else {
                result = String.format("%s%n%s", result, word);
                lineLength = word.length();
            }
        }
        return result;
    }

    public static void writeToFile(String name, String text) {
        try {
            FileWriter outFile = new FileWriter(name + ".txt");
            PrintWriter out = new PrintWriter(outFile);
            out.println(text);
            out.close();
        } catch (IOException e){
            e.printStackTrace();
        }
    }
}
